<template>
  <div>
    <ul class="tabUl">
      <li
        v-for="(item,inx) in tabList"
        :key="inx"
        :class="inx===activeInx && 'active'"
        @click="tabClick(inx)"
      >
        <span>{{item}}</span>
      </li>
    </ul>
    <div class="content">
      <slot name="content"></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tabList: Array,
    onTabChange: Function,
    inx: Number
  },
  methods: {
    tabClick(inx) {
      if (inx != this.activeInx) {
        this.activeInx = inx;
        this.onTabChange && this.onTabChange(inx);
      }
    }
  },
  data() {
    return {
      activeInx: this.inx || 0
    };
  }
};
</script>

<style lang="less" scoped>
.tabUl {
  display: flex;
  height: 2.8rem;
  justify-content: space-around;
  border-bottom: 1px solid #ddd;
  background-color: white;
  li {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    span {
      padding: 0.25rem 0.2rem;
    }
  }
  .active {
    span {
      color: #ff4544;
      border-bottom: 3px solid #ff4544;
    }
  }
}
.content {
  padding: 0.4rem;
}
</style>